/* This file was generated with JastAdd2 (http://jastadd.org) version R20121112 (r872) */
package icode;

import util.*;
import java.util.*;
/**
 * @production Code : {@link ASTNode} ::= <span class="component">{@link Instruction}*</span>;
 * @ast node
 * @declaredat /Users/yonk/Documents/workspace/YCompiler/icodespec/icode.ast:1
 */
public class Code extends ASTNode<ASTNode> implements Cloneable {
  /**
   * @apilevel low-level
   */
  public void flushCache() {
    super.flushCache();
  }
  /**
   * @apilevel internal
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Code clone() throws CloneNotSupportedException {
    Code node = (Code)super.clone();
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Code copy() {
      try {
        Code node = (Code)clone();
        if(children != null) node.children = (ASTNode[])children.clone();
        return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Code fullCopy() {
    try {
      Code tree = (Code) clone();
      tree.setParent(null);// make dangling
      if (children != null) {
        tree.children = new ASTNode[children.length];
        for (int i = 0; i < children.length; ++i) {
          if (children[i] == null) {
            tree.children[i] = null;
          } else {
            tree.children[i] = ((ASTNode) children[i]).fullCopy();
            ((ASTNode) tree.children[i]).setParent(tree);
          }
        }
      }
      return tree;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " +
        getClass().getName());
    }
  }
  /**
   * @ast method 
   * @aspect icodeToString
   * @declaredat /Users/yonk/Documents/workspace/YCompiler/icodespec/icodeToString.jadd:4
   */
  
    private final static int[] tabs = new int[]{8, 16, 32, 48, 64};
  /**
   * @ast method 
   * @aspect icodeToString
   * @declaredat /Users/yonk/Documents/workspace/YCompiler/icodespec/icodeToString.jadd:5
   */
  public String toString() {
        StringBuilder builder = new StringBuilder();
        TabbedBuffer lineBuffer = new TabbedBuffer(tabs);
        for (int i=0; i<getNumInstruction(); i++) {
            lineBuffer.clear();
            builder.append(getInstruction(i).toString(lineBuffer));
            builder.append('\n');
        }
        return builder.toString();
    }
  /**
   * @ast method 
   * 
   */
  public Code() {
    super();

    setChild(new List(), 0);

  }
  /**
   * @ast method 
   * 
   */
  public Code(List<Instruction> p0) {
    setChild(p0, 0);
  }
  /**
   * @apilevel low-level
   * @ast method 
   * 
   */
  protected int numChildren() {
    return 1;
  }
  /**
   * Replaces the Instruction list.
   * @param list The new list node to be used as the Instruction list.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void setInstructionList(List<Instruction> list) {
    setChild(list, 0);
  }
  /**
   * Retrieves the number of children in the Instruction list.
   * @return Number of children in the Instruction list.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public int getNumInstruction() {
    return getInstructionList().getNumChild();
  }
  /**
   * Retrieves the number of children in the Instruction list.
   * Calling this method will not trigger rewrites..
   * @return Number of children in the Instruction list.
   * @apilevel low-level
   * @ast method 
   * 
   */
  public int getNumInstructionNoTransform() {
    return getInstructionListNoTransform().getNumChildNoTransform();
  }
  /**
   * Retrieves the element at index {@code i} in the Instruction list..
   * @param i Index of the element to return.
   * @return The element at position {@code i} in the Instruction list.
   * @apilevel high-level
   * @ast method 
   * 
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Instruction getInstruction(int i) {
    return (Instruction)getInstructionList().getChild(i);
  }
  /**
   * Append an element to the Instruction list.
   * @param node The element to append to the Instruction list.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void addInstruction(Instruction node) {
    List<Instruction> list = (parent == null || state == null) ? getInstructionListNoTransform() : getInstructionList();
    list.addChild(node);
  }
  /**
   * @apilevel low-level
   * @ast method 
   * 
   */
  public void addInstructionNoTransform(Instruction node) {
    List<Instruction> list = getInstructionListNoTransform();
    list.addChild(node);
  }
  /**
   * Replaces the Instruction list element at index {@code i} with the new node {@code node}.
   * @param node The new node to replace the old list element.
   * @param i The list index of the node to be replaced.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void setInstruction(Instruction node, int i) {
    List<Instruction> list = getInstructionList();
    list.setChild(node, i);
  }
  /**
   * Retrieves the Instruction list.
   * @return The node representing the Instruction list.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public List<Instruction> getInstructions() {
    return getInstructionList();
  }
  /**
   * Retrieves the Instruction list.
   * <p><em>This method does not invoke AST transformations.</em></p>
   * @return The node representing the Instruction list.
   * @apilevel low-level
   * @ast method 
   * 
   */
  public List<Instruction> getInstructionsNoTransform() {
    return getInstructionListNoTransform();
  }
  /**
   * Retrieves the Instruction list.
   * @return The node representing the Instruction list.
   * @apilevel high-level
   * @ast method 
   * 
   */
  @SuppressWarnings({"unchecked", "cast"})
  public List<Instruction> getInstructionList() {
    List<Instruction> list = (List<Instruction>)getChild(0);
    list.getNumChild();
    return list;
  }
  /**
   * Retrieves the Instruction list.
   * <p><em>This method does not invoke AST transformations.</em></p>
   * @return The node representing the Instruction list.
   * @apilevel low-level
   * @ast method 
   * 
   */
  @SuppressWarnings({"unchecked", "cast"})
  public List<Instruction> getInstructionListNoTransform() {
    return (List<Instruction>)getChildNoTransform(0);
  }
}
